#pragma once

#include <base.h>

#define PAGE_4K (0x1000)
#define PAGE_4KSHIFT (12)
#define PAGE_4KMASK (0xfff)
#define PAGE_2M (0x200000)
#define PAGE_2MSHIFT (21)
#define PAGE_2MMASK (0x1fffff)

#define PAGE_P BIT(0)
#define PAGE_RW BIT(1)
#define PAGE_US BIT(2)
#define PAGE_WT BIT(3)
#define PAGE_CD BIT(4)
#define PAGE_AC BIT(5)
#define PAGE_DIRTY BIT(6)
#define PAGE_PAT BIT(7)
#define PAGE_GLOBAL BIT(8)
#define PAGE_NX BIT(63)

#define PT_ADDRMASK (0x0000fffffffff000)

void mm_paging_init();

int mm_paging_map_memory_4k(uint64_t *pagetable, uintptr_t vaddr, uintptr_t paddr, uint64_t flags);
int mm_paging_map_memory(uint64_t *pagetable, uintptr_t vaddr, uintptr_t paddr, uint64_t count_4k, uint64_t flags);

void mm_paging_map_physical_mem(uint64_t *pagetable);

uintptr_t mm_paging_get_paddr(uint64_t *pagetable, uintptr_t vaddr);

extern uint64_t *kernel_pagetable;